home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / plnk081.zip / pilot-link.0.8.1 / addresses.c < prev    next >
C/C++ Source or Header  |  1997-08-03  |  3KB  |  114 lines

  1. /* addresses.c:  Translate Pilot address book into a generic format
  2.  *
  3.  * Copyright (c) 1996, Kenneth Albanowski
  4.  *
  5.  * This is free software, licensed under the GNU Public License V2.
  6.  * See the file COPYING for details.
  7.  */
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include "pi-source.h"
  13. #include "pi-socket.h"
  14. #include "pi-address.h"
  15. #include "pi-dlp.h"
  16.  
  17.                   
  18. int main(int argc, char *argv[])
  19. {
  20.   struct pi_sockaddr addr;
  21.   int db;
  22.   int sd;
  23.   int i;
  24.   struct PilotUser U;
  25.   int ret;
  26.   unsigned char buffer[0xffff];
  27.   struct AddressAppInfo aai;
  28.  
  29.   if (argc < 2) {
  30.     fprintf(stderr,"usage:%s %s\n",argv[0],TTYPrompt);
  31.     exit(2);
  32.   }
  33.   if (!(sd = pi_socket(PI_AF_SLP, PI_SOCK_STREAM, PI_PF_PADP))) {
  34.     perror("pi_socket");
  35.     exit(1);
  36.   }
  37.     
  38.   addr.pi_family = PI_AF_SLP;
  39.   strcpy(addr.pi_device,argv[1]);
  40.   
  41.   ret = pi_bind(sd, (struct sockaddr*)&addr, sizeof(addr));
  42.   if(ret == -1) {
  43.     perror("pi_bind");
  44.     exit(1);
  45.   }
  46.  
  47.   ret = pi_listen(sd,1);
  48.   if(ret == -1) {
  49.     perror("pi_listen");
  50.     exit(1);
  51.   }
  52.  
  53.   sd = pi_accept(sd, 0, 0);
  54.   if(sd == -1) {
  55.     perror("pi_accept");
  56.     exit(1);
  57.   }
  58.  
  59.   /* Ask the pilot who it is. */
  60.   dlp_ReadUserInfo(sd,&U);
  61.   
  62.   /* Tell user (via Pilot) that we are starting things up */
  63.   dlp_OpenConduit(sd);
  64.   
  65.   /* Open the Address book's database, store access handle in db */
  66.   if(dlp_OpenDB(sd, 0, 0x80|0x40, "AddressDB", &db) < 0) {
  67.     puts("Unable to open AddressDB");
  68.     dlp_AddSyncLogEntry(sd, "Unable to open AddressDB.\n");
  69.     exit(1);
  70.   }
  71.   
  72.   dlp_ReadAppBlock(sd, db, 0, buffer, 0xffff);
  73.   unpack_AddressAppInfo(&aai, buffer, 0xffff);
  74.   
  75.   for (i=0;1;i++) {
  76.       struct Address a;
  77.       int attr, category;
  78.       int j;
  79.                                  
  80.       int len = dlp_ReadRecordByIndex(sd, db, i, buffer, 0, 0, &attr, &category);
  81.       if(len<0)
  82.           break;
  83.           
  84.       /* Skip deleted records */
  85.       if((attr & dlpRecAttrDeleted) || (attr & dlpRecAttrArchived))
  86.           continue;
  87.           
  88.     unpack_Address(&a, buffer, len);
  89.     
  90.     printf("Category: %s\n", aai.category.name[category]);
  91.     for(j=0;j<19;j++) {
  92.       if(a.entry[j]) {
  93.         int l = j;
  94.         if ( (l >= entryPhone1) && ( l <= entryPhone5))
  95.           printf("%s: %s\n", aai.phoneLabels[a.phoneLabel[l-entryPhone1]], a.entry[j]);
  96.         else
  97.           printf("%s: %s\n", aai.labels[l], a.entry[j]);
  98.       }
  99.     }
  100.     printf("\n");
  101.  
  102.     free_Address(&a);
  103.   }
  104.  
  105.   /* Close the database */
  106.   dlp_CloseDB(sd, db);
  107.  
  108.   dlp_AddSyncLogEntry(sd, "Read addresses from Pilot.\n");
  109.  
  110.   pi_close(sd);  
  111.   exit(0);
  112. }
  113.  
  114.